local function config_cmp(cmp)
  cmp.setup {
    mapping = cmp.mapping.preset.insert {
      ['<c-b>'] = cmp.mapping.scroll_docs(-4),
      ['<c-f>'] = cmp.mapping.scroll_docs(4),
      ['<c-space>'] = cmp.mapping.complete(),
      ['<c-e>'] = cmp.mapping.abort(),
      ['<cr>'] = cmp.mapping.confirm { select = true } },
    window = {
      completion = cmp.config.window.bordered(),
      documentation = cmp.config.window.bordered(),
    },
    snippet = {
      expand = function(args)
        require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
      end,
    },
    formatting = {
      fields = { 'kind', 'abbr', 'menu' },
      format = function(_, item)
        local icons = require("next.utils.icon").kinds
        item.menu = item.kind
        if icons[item.kind] then
          item.kind = icons[item.kind]
        end
        return item
      end,
    },
    sources = {
      { name = 'lazydev' },
      { name = "nvim_lsp" },
      { name = 'luasnip', option = { use_show_condition = false } },
      { name = "buffer" },
      { name = "nvim_lua" },
      { name = "path" },
      { name = "crates" },
      { name = 'emmet' },
      { name = 'orgmode' },
    },
  }

  cmp.setup.cmdline({ "/", "?" }, {
    sources = {
      { name = "buffer" },
    },
    mapping = cmp.mapping.preset.cmdline(),
  })


  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources({
      { name = 'path' }
    }, {
      {
        name = 'cmdline',
        option = {
          ignore_cmds = { 'Man', '!' }
        }
      }
    })
  })
end
return {
  {
    "hrsh7th/nvim-cmp",
    dependencies = {
      "L3MON4D3/LuaSnip",
      "saadparwaiz1/cmp_luasnip",
      "rafamadriz/friendly-snippets",
      { 'jackieaskins/cmp-emmet', build = 'npm run release' },
      "TwIStOy/luasnip-snippets",
      "hrsh7th/cmp-nvim-lsp",
      "hrsh7th/cmp-buffer",
      "hrsh7th/cmp-path",
      "hrsh7th/cmp-cmdline",
      "Saecki/crates.nvim"
    },

    config = function()
      local cmp = require "cmp"
      config_cmp(cmp)
      require("luasnip.loaders.from_vscode").lazy_load()
      require("luasnip.loaders.from_lua").load({ paths = vim.fn.stdpath('config') .. '/snippets' })
    end,
  }
}
